#include "../2_source/server.hpp"


void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("new connection:%p", conn.get());
}
void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("close connection:%p", conn.get());
}
void OnMessage(const PtrConnection& conn, Buffer* buf)
{ 
    DBG_LOG("%s", buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadableSize());
    string str = "hello,world~!";
    conn->Send(str.c_str(), str.size());
    // conn->ShutDown();
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.SetClosedCallback(OnClosed);
    // server.SetAnyEventCallback();
    server.StartServer();


    return 0;
}